﻿using Aishow.BLL;
using Aishow.IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Aishow.Website
{
    public partial class AvatarEdit : System.Web.UI.Page
    {
        IUserManager manager = new UserManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                var user = IdentityManager.ReadUser();
                if(user == null)
                {
                    Response.Redirect("login.aspx?ReturnUrl=AvatarEdit.aspx");
                }
            }
        }

        protected void btnAvatar_Click(object sender, EventArgs e)
        {
            if(IsValid)
            {
                var user = IdentityManager.ReadUser();
                user.Avatar = hfAvatar.Value;
                var result= manager.EditAvatar(user);

                if (result.StatusCode == Model.OperResult.StatusCode.Succeed)
                {
                    Response.Redirect("Personal.aspx");
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "editerror", $"alert('{result.Message}')", true);
                }
            }
        }

    }
}